package com.kkb.controller;

import com.github.pagehelper.PageInfo;
import com.kkb.pojo.Hospitalization;
import com.kkb.pojo.PricePeople;
import com.kkb.service.HosSettleService;
import com.kkb.service.PricePeopleService;
import com.kkb.vo.ResultVO;
import com.kkb.vo.SettleQueryVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.xml.transform.Result;

/**
 * 住院结算的单独 Controller
 */
@Controller
@RequestMapping("settle")
@ResponseBody
public class HosSettleController {

    @Resource
    private HosSettleService hosSettleService;

    @Resource
    private PricePeopleService pricePeopleService;

    /**
     * 根据病历号和姓名进行 HosRegister 和 Hospitalization 的两表联查
     * @param index
     * @param size
     * @param vo
     * @return
     */
    @RequestMapping(value = "list",method = RequestMethod.GET)
    public ResultVO<Hospitalization> selectInPage(Integer index, Integer size, SettleQueryVO vo){
        PageInfo<Hospitalization> hospitalizationPageInfo = hosSettleService.selectInPage(index, size, vo);
        return hospitalizationPageInfo != null ?
                new ResultVO<>(hospitalizationPageInfo):new ResultVO<>(400,"暂无数据");
    }

    /**
     * 查询挂号表中的病人和其在医院的消费项目的所有内容
     * @param hosId
     * @return
     */
    @RequestMapping(value = "{id}",method = RequestMethod.GET)
    public ResultVO<PricePeople> selectRegisterAndChargeProj(@PathVariable("id") Integer hosId){
        PageInfo<PricePeople> pricePeoplePageInfo = pricePeopleService.selectByHosRegisterId(1,4,hosId);
        return pricePeoplePageInfo != null ? new ResultVO<>(pricePeoplePageInfo): new ResultVO<>(404,"暂无数据");
    }

    /**
     * 结算
     * @param id HosRegisterId 病例号Id
     * @return
     */
    @RequestMapping(value = "{id}",method = RequestMethod.DELETE)
    public ResultVO settlement(@PathVariable("id") Integer id){
        return pricePeopleService.deleteByHosRegisterId(id) >0 ? new ResultVO(): new ResultVO(404,"结算失败，暂无消费项目");
    }

}
